package gold.digger;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC844 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public boolean backspaceCompare(String s, String t) {
            return getFinalStr(s).equals(getFinalStr(t));
        }

        public String getFinalStr(String str) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < str.length(); i++) {
                if (str.charAt(i) == '#') {
                    if (sb.length() > 0) sb.deleteCharAt(sb.length() - 1);
                } else sb.append(str.charAt(i));
            }

            return sb.toString();
        }

    }

    public void run() {

        Solution solution = new Solution();
        System.out.println(solution.backspaceCompare("y#fo##f", "y#f#o##f"));
    }

    public static void main(String[] args) throws Exception {
        LC844 an = new LC844();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
